{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "tags": [
     "remove-cell"
    ]
   },
   "outputs": [],
   "source": [
    "import sys\n",
    "import os\n",
    "if not any(path.endswith('textbook') for path in sys.path):\n",
    "    sys.path.append(os.path.abspath('../../..'))\n",
    "from textbook_utils import *"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "(ch:linear)=\n",
    "# Linear Models"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "At this point in the book,\n",
    "we've covered the four stages of the data science lifecycle to different extents.\n",
    "We've talked about formulating questions and obtaining and cleaning data, and we've used exploratory data analysis to better understand the data. In this chapter, we extend the constant model introduced in {numref}`Chapter %s <ch:modeling>` to the *linear model*. Linear models are a popular tool in the last stage of the lifecycle: understanding the world."
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Knowing how to fit linear models opens the door to all kinds of useful data analyses.\n",
    "We can use these models to make *predictions*---for example,\n",
    "environmental scientists developed a linear model to predict air quality based on air sensor measurements and weather conditions (see {numref}`Chapter %s <ch:pa>`). \n",
    "In that case study, understanding how measurements from two instruments varied\n",
    "enabled us to calibrate inexpensive sensors and improve their air quality readings. \n",
    "We can also use these models to make *inferences* about the form of a relationship between features---for example, \n",
    "veterinarians used a linear model (see {numref}`Chapter %s <ch:donkey>`) to infer the coefficients for length and girth for a donkey's weight: $ Length ~+ ~ 2 \\times Girth ~-~175 $. \n",
    "In that case study, the model enables vets working in the field to prescribe medication for sick donkeys. \n",
    "Models can also help *describe relationships* and provide insights---for example, in this chapter, we explore relationships between factors correlated with upward mobility, such as commute time, income inequality, and the quality of K–12 education. We carry out a descriptive analysis that follows an analysis social scientists have used to shape public conversation and inform policy recommendations."
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We start by describing the simple linear model, which\n",
    "summarizes the relationship between two features with a line.\n",
    "We explain how to fit this line to data using the loss minimization approach introduced in {numref}`Chapter %s <ch:modeling>`.\n",
    "Then we introduce the multiple linear model, which models one feature using multiple, other features.\n",
    "To fit such a model, we use linear algebra and reveal the geometry behind fitting a linear model with squared error loss.\n",
    "Finally, we cover feature engineering techniques that let us include categorical features and transformed features when building models."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
